﻿using System;
using System.Collections.Generic;
using System.Xml;
using YArchitech.Revit.MEP.Modeling;

namespace HYRElectric.WirePlace
{
	public class LineTypeXMLManage
	{
		public LineTypeXMLManage(string xmlFilePath)
		{
			this.xmlDoc = new XmlDocument();
			this.xmlDoc.Load(xmlFilePath);
			this.xmlNode = this.xmlDoc.DocumentElement;
			this.filePath = xmlFilePath;
		}

		public List<LineType> GetLineType()
		{
			List<LineType> result;
			try
			{
				if (this.xmlNode != null)
				{
					List<LineType> list = new List<LineType>();
					foreach (object obj in this.xmlNode.ChildNodes)
					{
						XmlNode xmlNode = (XmlNode)obj;
						list.Add(new LineType
						{
							Title = xmlNode.Attributes["Title"].Value,
							Name = xmlNode.Attributes["Name"].Value,
							Width = Convert.ToDouble(xmlNode.Attributes["Width"].Value),
							Color = Convert.ToInt32(xmlNode.Attributes["Color"].Value)
						});
					}
					result = list;
				}
				else
				{
					result = null;
				}
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		private XmlDocument xmlDoc;

		private string filePath;

		private XmlNode xmlNode;
	}
}
